//=============================================================================
//
//  Copyright (c) Kitware, Inc.
//  All rights reserved.
//  See LICENSE.txt for details.
//
//  This software is distributed WITHOUT ANY WARRANTY; without even
//  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
//  PURPOSE.  See the above copyright notice for more information.
//
//  Copyright 2013 Sandia Corporation.
//  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
//  the U.S. Government retains certain rights in this software.
//
//=============================================================================
#ifndef __dax_Benchmarks_Mandlebulb_CoolWarmColorMap_h
#define __dax_Benchmarks_Mandlebulb_CoolWarmColorMap_h

#include <dax/Types.h>
#include <dax/math/Compare.h>
#include <dax/internal/ExportMacros.h>

#include <algorithm>

namespace mandle {

class CoolWarmColorMap {
public:
  typedef dax::Tuple<unsigned char, 3> ColorType;

  DAX_CONT_EXPORT CoolWarmColorMap()
  {
    const ColorType *coolWarmTable = GetCoolWarmTable();
    std::copy(coolWarmTable, coolWarmTable+NUM_COLORS, this->Colors);
  }

  DAX_EXEC_CONT_EXPORT
  const ColorType &GetColor(dax::Scalar scalar) const
  {
    scalar = dax::math::Max(dax::Scalar(0.0),scalar);
    scalar = dax::math::Min(dax::Scalar(0.9999),scalar);

    int index = (int)(NUM_COLORS*scalar);
    return this->Colors[index];
  }

private:
  static const int NUM_COLORS = 257;
  ColorType Colors[NUM_COLORS];

  DAX_CONT_EXPORT
  static const ColorType *GetCoolWarmTable() {
    static const ColorType coolWarmTable[NUM_COLORS] = {
      ColorType(59,76,192),
      ColorType(60,78,194),
      ColorType(61,80,195),
      ColorType(62,81,197),
      ColorType(63,83,198),
      ColorType(64,85,200),
      ColorType(66,87,201),
      ColorType(67,88,203),
      ColorType(68,90,204),
      ColorType(69,92,206),
      ColorType(70,93,207),
      ColorType(71,95,209),
      ColorType(73,97,210),
      ColorType(74,99,211),
      ColorType(75,100,213),
      ColorType(76,102,214),
      ColorType(77,104,215),
      ColorType(79,105,217),
      ColorType(80,107,218),
      ColorType(81,109,219),
      ColorType(82,110,221),
      ColorType(84,112,222),
      ColorType(85,114,223),
      ColorType(86,115,224),
      ColorType(87,117,225),
      ColorType(89,119,226),
      ColorType(90,120,228),
      ColorType(91,122,229),
      ColorType(93,123,230),
      ColorType(94,125,231),
      ColorType(95,127,232),
      ColorType(96,128,233),
      ColorType(98,130,234),
      ColorType(99,131,235),
      ColorType(100,133,236),
      ColorType(102,135,237),
      ColorType(103,136,238),
      ColorType(104,138,239),
      ColorType(106,139,239),
      ColorType(107,141,240),
      ColorType(108,142,241),
      ColorType(110,144,242),
      ColorType(111,145,243),
      ColorType(112,147,243),
      ColorType(114,148,244),
      ColorType(115,150,245),
      ColorType(116,151,246),
      ColorType(118,153,246),
      ColorType(119,154,247),
      ColorType(120,156,247),
      ColorType(122,157,248),
      ColorType(123,158,249),
      ColorType(124,160,249),
      ColorType(126,161,250),
      ColorType(127,163,250),
      ColorType(129,164,251),
      ColorType(130,165,251),
      ColorType(131,167,252),
      ColorType(133,168,252),
      ColorType(134,169,252),
      ColorType(135,171,253),
      ColorType(137,172,253),
      ColorType(138,173,253),
      ColorType(140,174,254),
      ColorType(141,176,254),
      ColorType(142,177,254),
      ColorType(144,178,254),
      ColorType(145,179,254),
      ColorType(147,181,255),
      ColorType(148,182,255),
      ColorType(149,183,255),
      ColorType(151,184,255),
      ColorType(152,185,255),
      ColorType(153,186,255),
      ColorType(155,187,255),
      ColorType(156,188,255),
      ColorType(158,190,255),
      ColorType(159,191,255),
      ColorType(160,192,255),
      ColorType(162,193,255),
      ColorType(163,194,255),
      ColorType(164,195,254),
      ColorType(166,196,254),
      ColorType(167,197,254),
      ColorType(168,198,254),
      ColorType(170,199,253),
      ColorType(171,199,253),
      ColorType(172,200,253),
      ColorType(174,201,253),
      ColorType(175,202,252),
      ColorType(176,203,252),
      ColorType(178,204,251),
      ColorType(179,205,251),
      ColorType(180,205,251),
      ColorType(182,206,250),
      ColorType(183,207,250),
      ColorType(184,208,249),
      ColorType(185,208,248),
      ColorType(187,209,248),
      ColorType(188,210,247),
      ColorType(189,210,247),
      ColorType(190,211,246),
      ColorType(192,212,245),
      ColorType(193,212,245),
      ColorType(194,213,244),
      ColorType(195,213,243),
      ColorType(197,214,243),
      ColorType(198,214,242),
      ColorType(199,215,241),
      ColorType(200,215,240),
      ColorType(201,216,239),
      ColorType(203,216,238),
      ColorType(204,217,238),
      ColorType(205,217,237),
      ColorType(206,217,236),
      ColorType(207,218,235),
      ColorType(208,218,234),
      ColorType(209,219,233),
      ColorType(210,219,232),
      ColorType(211,219,231),
      ColorType(213,219,230),
      ColorType(214,220,229),
      ColorType(215,220,228),
      ColorType(216,220,227),
      ColorType(217,220,225),
      ColorType(218,220,224),
      ColorType(219,220,223),
      ColorType(220,221,222),
      ColorType(221,221,221),
      ColorType(222,220,219),
      ColorType(223,220,218),
      ColorType(224,219,216),
      ColorType(225,219,215),
      ColorType(226,218,214),
      ColorType(227,218,212),
      ColorType(228,217,211),
      ColorType(229,216,209),
      ColorType(230,216,208),
      ColorType(231,215,206),
      ColorType(232,215,205),
      ColorType(232,214,203),
      ColorType(233,213,202),
      ColorType(234,212,200),
      ColorType(235,212,199),
      ColorType(236,211,197),
      ColorType(236,210,196),
      ColorType(237,209,194),
      ColorType(238,209,193),
      ColorType(238,208,191),
      ColorType(239,207,190),
      ColorType(240,206,188),
      ColorType(240,205,187),
      ColorType(241,204,185),
      ColorType(241,203,184),
      ColorType(242,202,182),
      ColorType(242,201,181),
      ColorType(243,200,179),
      ColorType(243,199,178),
      ColorType(244,198,176),
      ColorType(244,197,174),
      ColorType(245,196,173),
      ColorType(245,195,171),
      ColorType(245,194,170),
      ColorType(245,193,168),
      ColorType(246,192,167),
      ColorType(246,191,165),
      ColorType(246,190,163),
      ColorType(246,188,162),
      ColorType(247,187,160),
      ColorType(247,186,159),
      ColorType(247,185,157),
      ColorType(247,184,156),
      ColorType(247,182,154),
      ColorType(247,181,152),
      ColorType(247,180,151),
      ColorType(247,178,149),
      ColorType(247,177,148),
      ColorType(247,176,146),
      ColorType(247,174,145),
      ColorType(247,173,143),
      ColorType(247,172,141),
      ColorType(247,170,140),
      ColorType(247,169,138),
      ColorType(247,167,137),
      ColorType(247,166,135),
      ColorType(246,164,134),
      ColorType(246,163,132),
      ColorType(246,161,131),
      ColorType(246,160,129),
      ColorType(245,158,127),
      ColorType(245,157,126),
      ColorType(245,155,124),
      ColorType(244,154,123),
      ColorType(244,152,121),
      ColorType(244,151,120),
      ColorType(243,149,118),
      ColorType(243,147,117),
      ColorType(242,146,115),
      ColorType(242,144,114),
      ColorType(241,142,112),
      ColorType(241,141,111),
      ColorType(240,139,109),
      ColorType(240,137,108),
      ColorType(239,136,106),
      ColorType(238,134,105),
      ColorType(238,132,103),
      ColorType(237,130,102),
      ColorType(236,129,100),
      ColorType(236,127,99),
      ColorType(235,125,97),
      ColorType(234,123,96),
      ColorType(233,121,95),
      ColorType(233,120,93),
      ColorType(232,118,92),
      ColorType(231,116,90),
      ColorType(230,114,89),
      ColorType(229,112,88),
      ColorType(228,110,86),
      ColorType(227,108,85),
      ColorType(227,106,83),
      ColorType(226,104,82),
      ColorType(225,102,81),
      ColorType(224,100,79),
      ColorType(223,98,78),
      ColorType(222,96,77),
      ColorType(221,94,75),
      ColorType(220,92,74),
      ColorType(218,90,73),
      ColorType(217,88,71),
      ColorType(216,86,70),
      ColorType(215,84,69),
      ColorType(214,82,67),
      ColorType(213,80,66),
      ColorType(212,78,65),
      ColorType(210,75,64),
      ColorType(209,73,62),
      ColorType(208,71,61),
      ColorType(207,69,60),
      ColorType(205,66,59),
      ColorType(204,64,57),
      ColorType(203,62,56),
      ColorType(202,59,55),
      ColorType(200,57,54),
      ColorType(199,54,53),
      ColorType(198,51,52),
      ColorType(196,49,50),
      ColorType(195,46,49),
      ColorType(193,43,48),
      ColorType(192,40,47),
      ColorType(190,37,46),
      ColorType(189,34,45),
      ColorType(188,30,44),
      ColorType(186,26,43),
      ColorType(185,22,41),
      ColorType(183,17,40),
      ColorType(181,11,39),
      ColorType(180,4,38)
    };
    return coolWarmTable;
  }
};

} // namespace mandle

#endif //__dax_Benchmarks_Mandlebulb_CoolWarmColorMap_h
